﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EditAnyString.Providers;

namespace EditAnyString.Extensions
{
	public static class CacheProviderExtensions
	{
		public static T Get<T>( this IEASCacheProvider cacheProvider, string key, Func<T> acquire )
		{
			return Get( cacheProvider, key, 60, acquire );
		}

		public static T Get<T>( this IEASCacheProvider cacheProvider, string key, int cacheTime, Func<T> acquire )
		{
			if( cacheProvider.IsSet( key ) )
			{
				return cacheProvider.Get<T>( key );
			}
			else
			{
				var result = acquire();
				cacheProvider.Set( key, result, cacheTime );
				return result;
			}
		}
	}
}
